import { HttpSrv } from 'lfun-bg-comp';
import { PageParams } from '..';

export interface SearchStuInfo {
  student_name?: string;
  id_type?: string;
  id_number?: string;
}

export interface TransferinInfo {
  student_id: any;
  province_id: string;
  city_id: string;
  area_id: string;
  district_id: string;
  transfer_in_type: string;
  country_no: string;
  school_id: any;
  school_name: string;
  session: string;
  attached_class: string;
  grade_id: string;
  grade_name: string;
  class_id: string;
  classes: string;
  major_id: string;
  transfer_time: string;
  transfer_reason: string;
  status: string;
  doc_upload: string;
  id: any;
  relation_id: any;
}

export interface TransferinFromoutsideInfo {
  student_baseinfo: {
    student_name: string;
    enrollment_number: string;
    birthday: string;
    student_gender: string;
    id_type: string;
    id_number: string;
    ethnicity: string;
    edu_number: string;
    residence_address_detail: string;
    residence_district: string;
    student_id: string;
  };
  student_edu_info_in: {
    student_id: string;
    province_id: string;
    city_id: string;
    area_id: string;
    district_id: string;
    transfer_in_type: string;
    country_no: string;
    school_id: string;
    school_name: string;
    session: string;
    attached_class: string;
    grade_id: string;
    grade_name: string;
    class_id: string;
    classes: string;
    major_id: string;
    transfer_time: string;
    transfer_reason: string;
    status: string;
    doc_upload: string;
    id: string;
    relation_id: string;
  };
  student_edu_info_out: {
    student_id: string;
    province_id: string;
    city_id: string;
    area_id: string;
    district_id: string;
    transfer_in_type: string;
    country_no: string;
    school_id: string;
    school_name: string;
    session: string;
    attached_class: string;
    grade_id: string;
    grade_name: string;
    class_id: string;
    classes: string;
    major_id: string;
    transfer_time: string;
    transfer_reason: string;
    status: string;
    doc_upload: string;
    id: string;
    relation_id: string;
  };
}
export interface TransferoutInfo {
  student_id: any;
  province_id: string;
  city_id: string;
  area_id: string;
  district_id: string;
  transfer_in_type: string;
  edu_number: string;
  school_id: any;
  school_name: string;
  session: string;
  attached_class: string;
  grade_id: string;
  grade_name: string;
  class_id: string;
  classes: string;
  major_id: string;
  transfer_time: string;
  transfer_reason: string;
  status: string;
  doc_upload: string | null; // Assuming empty string should be treated as null
  id: any;
  relation_id: any;
}

export interface TransactionPageParams {
  student_name: string;
  student_gender: string;
  school_id: string;
  apply_user: string;
  edu_no: string;
  audit_status: string;
}

export interface InnerTransactionParams {
  student_id: any;
  student_name: string;
  transaction_type: string;
  transaction_reason: string;
}

export interface InnerTransactionSearchParams {
  borough: string;
  school_id: string;
  student_name: string;
  student_gender: string;
  edu_number: string;
  class_id: string;
}

// 获取列表
export const getStuInfoList = (params: any, page: any, per_page: any): Promise<any> =>
  HttpSrv().get('/school/v1/current-student/temporary-study', {
    params: { ...params, page, per_page },
  });

// 获取单个学生
export const getStuInfo = (params: SearchStuInfo & PageParams): Promise<any> =>
  HttpSrv().get('/school/v1/news-students-view/newstudent', {
    params: { page: 1, pre_page: 1, ...params, approval_status: 'assignment' },
  });

export const getStuBaseInfo = (student_id: string): Promise<any> =>
  HttpSrv().get('/school/v1/news-students-info/newstudentbaseinfo', { params: { student_id } });

// 系统内转出
export const transferin = (info: TransferinInfo): Promise<any> =>
  HttpSrv().patch('/school/v1/current-student/transferin', info);

// 取消临时就读
export const temporaryStudyCancel = (student_temporary_study_id: any): Promise<any> =>
  HttpSrv().patch(
    `/school/v1/current-student/temporary-study-cancel?student_temporary_study_id=${student_temporary_study_id}`
  );

// 新增临时就读
export const transferinFromoutside = (info: TransferinFromoutsideInfo): Promise<any> =>
  HttpSrv().patch('/school/v1/current-student/temporary-study', info);

// 学生关键信息
export const getStudentkeyinfo = (student_id: string): Promise<any> =>
  HttpSrv().get('/school/v1/current-student/studentkeyinfo', { params: { student_id } });

// 转出
export const transferout = (student_id: string, parmas: TransferoutInfo): Promise<any> =>
  HttpSrv().patch(`/school/v1/current-student/transferout-tooutside?student_id=${student_id}`, parmas);
// 撤回
export const transferinCancel = (transferin_id: string, parmas?: any): Promise<any> =>
  HttpSrv().patch(`/school/v1/current-student/transaction-cancel?transferin_id=${transferin_id}`, parmas);
// 转学管理
export const transactionPage = (params: TransactionPageParams, page: number, per_page: number): Promise<any> =>
  HttpSrv().get('/school/v1/current-student/student-transaction', {
    params: { ...params, page, per_page },
  });

// 审核转学
export const transactionAudit = (
  process_instance_id: string,
  transferin_audit_action: 'needaudit' | 'pass' | 'refuse',
  audit_remark: string
): Promise<any> =>
  HttpSrv().patch('/school/v1/current-student/transferin-audit', {
    process_instance_id,
    transferin_audit_action,
    audit_remark,
  });
// 获取单个转学信息
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const getTransactionInfo = (apply_id: any): Promise<any> =>
  HttpSrv().get('/school/v1/current-student/student-transaction-info', { params: { apply_id } });
// 新增异动
export const innerTransaction = (params: InnerTransactionParams): Promise<any> =>
  HttpSrv().post('/school/v1/current-students-inner-transaction/', { ...params });

// 异动分页
export const pageTransaction = (params: InnerTransactionSearchParams, page: number, per_page: number): Promise<any> =>
  HttpSrv().get('/school/v1/current-students-inner-transaction/page', { params: { ...params, page, per_page } });

export const exportStuInfo = (params: SearchStuInfo): Promise<any> =>
  HttpSrv().post('/school/v1/current-student/current-student-export', {
    params: { ...params, approval_status: 'assignment' },
  });
